package com.hns.tool.export.pdf;

import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;

/**
 * PDF单元格实体
 * @author:Fisher
 * @email:zhuangcaijin@126.com
 * @version Revision 2.0.0
 */
public class PdfCellEntity {
	/** 
	 * 单元格内容 
	 */
	private String cellValue;

	/** 
	 * 跨列数 
	 */
	private Integer colSpan;

	/** 
	 * 跨行数 
	 */
	private Integer rowSpan;

	/** 
	 * 字体 
	 */
	private Font font;

	/** 
	 * 单元格边宽度 
	 */
	private Float borderWidth;

	/** 
	 * 是否水平垂直对齐 
	 */
	private Boolean isVerticalCenter;

	/** 
	 * 水平对齐方式 
	 */
	private Integer horizontalAlignment;

	/** 
	 * 垂直对齐方式 
	 */
	private Integer verticalAlignment;

	/**
	 * 得到单元格
	 * @return 单元格
	 * @author:Fisher
	 * @email:zhuangcaijin@126.com
	 */
	public PdfPCell getCell() {
		if (font == null) {// 字体为空则改为默认字体
			// 默认字体
			BaseFont baseFont = null;
			try {
				baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
			} catch (Exception e) {
				e.printStackTrace();
			}
			font = new Font(baseFont, 10, Font.BOLD);
		}
		// 初始化单元格
		PdfPCell h = new PdfPCell(new Paragraph(cellValue, font));
		// 单元格跨行
		if (rowSpan != null) {
			h.setRowspan(rowSpan);
		}
		// 单元格跨列
		if (colSpan != null) {
			h.setColspan(colSpan);
		}
		// 设置单元格Border宽度
		if (borderWidth != null) {
			h.setBorderWidth(borderWidth);
		}
		// 设置水平对齐方式
		if (horizontalAlignment != null) {
			h.setHorizontalAlignment(horizontalAlignment);
		} else {
			h.setHorizontalAlignment(Element.ALIGN_CENTER);
		}
		// 设置垂直对齐方式
		if (isVerticalCenter != null && isVerticalCenter) {
			h.setVerticalAlignment(Element.ALIGN_MIDDLE);
		} else if (verticalAlignment != null) {
			h.setVerticalAlignment(verticalAlignment);
		}
		return h;
	}

	public String getCellValue() {
		return cellValue != null ? cellValue.trim() : cellValue;
	}

	public PdfCellEntity setCellValue(String cellValue) {
		this.cellValue = cellValue;
		return this;
	}

	public Integer getColSpan() {
		return colSpan;
	}

	public PdfCellEntity setColSpan(Integer colSpan) {
		this.colSpan = colSpan;
		return this;
	}

	public Integer getRowSpan() {
		return rowSpan;
	}

	public PdfCellEntity setRowSpan(Integer rowSpan) {
		this.rowSpan = rowSpan;
		return this;
	}

	public Font getFont() {
		return font;
	}

	public PdfCellEntity setFont(Font font) {
		this.font = font;
		return this;
	}

	public Float getBorderWidth() {
		return borderWidth;
	}

	public PdfCellEntity setBorderWidth(Float borderWidth) {
		this.borderWidth = borderWidth;
		return this;
	}

	public Boolean getIsVerticalCenter() {
		return isVerticalCenter;
	}

	public PdfCellEntity setIsVerticalCenter(Boolean isVerticalCenter) {
		this.isVerticalCenter = isVerticalCenter;
		return this;
	}

	public Integer getHorizontalAlignment() {
		return horizontalAlignment;
	}

	public PdfCellEntity setHorizontalAlignment(Integer horizontalAlignment) {
		this.horizontalAlignment = horizontalAlignment;
		return this;
	}

	public Integer getVerticalAlignment() {
		return verticalAlignment;
	}

	public PdfCellEntity setVerticalAlignment(Integer verticalAlignment) {
		this.verticalAlignment = verticalAlignment;
		return this;
	}

}
